#include <UnitTest++.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "LZ77.h"
#include "logger.h"

const std::string names [] = {"Jorge", "Maiko", "Andrea"};

TEST(testCompressFunction)
{
    const char* expected = "anita lav(4,4) tina";
    const char* compressed = LZ77::compress("anita lava la tina");
    CHECK_EQUAL(expected, compressed);
}

TEST(testCompress)
{
    const char* expected = "anita lav(4,4) tin(12,5)(12,6)";
    const char* compressed = LZ77::compress("anita lava la tina tina tina");
    CHECK_EQUAL(expected, compressed);
}

TEST(testCompressJAJAJA)
{
    const char* expected = "ajaj(0,4)(0,8)(0,6)";
    const char* data = "ajajajajajajajajajajaj";
    const char* compressed = LZ77::compress(data);
    const char* decompressed = LZ77::decompress(compressed);
    CHECK_EQUAL(data, decompressed);
}

TEST(testCompressWithTwo)
{
    const char* expected = "anita lav(4,4) tina de cris(14,4)";
    const char* compressed = LZ77::compress("anita lava la tina de cristina");
    CHECK_EQUAL(expected, compressed);
}

TEST(testDecompressFunction)
{
    const char* expected = "anita lava la tina";
    const char* decompressed = LZ77::decompress("anita lava(5,3) tina");
    CHECK_EQUAL(expected, decompressed);
}

void writeTestFile(char*& buffer)
{
    std::string str;

    for (int i = 0; i < 1000; i++)
    {
        int random = rand() % 3;
        str += names[random];
        //        test.append(" ");
    }

    buffer = new char[str.size()];
    str.copy(buffer, str.size(), 0);
}

TEST(testSizeFile)
{
    char* testStr;
    writeTestFile(testStr);
    const char* compressed = LZ77::compress(testStr);

    if (strlen(testStr) < strlen(compressed))
    {
        CHECK(false);
    }
    delete testStr;
}

//TEST(testGetLongerFunction)
//{
//    const char* expected = "tina";
//    int pos = 26;
//    const char* longest = LZ77::findLongest("anita lava la tina de cristina", 
//    pos, "anita lava la tina de cris").c_str();
//    CHECK_EQUAL(expected, longest);
//}
